cqrbdp.drawTodyBarTest = function() {
    var myChart = echarts.init(document.getElementById('barmain'));
    var colors = ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'];
    var option = {
        // color: ['#72D8FF', '#EC5F5F', '#4CE73C', '#1693FF', '#F4D604'],
        //全局调色板，按新闻、论坛、微信、新浪微博、腾讯微博顺序
        title: {
            show: false,
            top: 'top',
            left: 'center',
            text: '今日数据量',
            textStyle: {
                color: '#fff',
                fontWeight: 'bold',
                fontSize: 16
            }
        },
        grid: {
            show: false,
            x: 160,
            y: 50,
            containLabel: false,
            height: 230,
            width: 385,
            borderColor: 'rgba(0,0,0,0)'
        },
        tooltip: {
            show: true,
            showContent: true,
            trigger: 'axis',
            formatter: '{b}: {c}'
        },
        xAxis: [{
            type: 'category',
            show:false,
            boundaryGap: true,
            axisLine: {
                show: true,
                onZero: false,
                lineStyle: {
                    color: '#6acce4',
                    width: 1
                }
            },
            axisTick: {
                show: false,
                inside: false,
                lineStyle: {
                    color: '#6acce4',
                }
            },
            axisLabel: {
                show: true,
                interval: 0,
                margin: 25,
                textStyle: {
                    color: '#fff',
                    fontWeight: 'bold',
                    fontSize: 15
                }
            },
            splitLine: {
                show: false,
            },
            splitArea: {
                show: false,
                interval: 0
            },
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        }],
        yAxis: [{
            type: 'value',
            axisLine: {
                show: true,
                onZero: false,
                lineStyle: {
                    color: '#6acce4',
                    width: 1
                }
            },
            axisTick: {
                show: true,
                lineStyle: {
                    color: '#6acce4',
                }
            },
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#6acce4'
                },
                // formatter: function(value, index) {
                //     if (value / 10000 >= 1 && value / 10000 < 100) {
                //         return (value / 10000) + "W";
                //     } else if (value / 1000000 >= 1) {
                //         return (value / 1000000) + "M";
                //     };
                //     return value;
                // }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#3B3E43'
                }
            },
        }],
        series: [{
            name: '数据量',
            type: 'bar',
            legendHoverLink: false,
            itemStyle: {
                normal: {
                    // barBorderRadius: 15,
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}',
                        textStyle: {
                            color: '#99D4ED',
                            fontSize: 14
                        }
                    },
                    color: function(param) {
                        return colors[param.dataIndex];
                    }
                },
                emphasis: {
                    // barBorderRadius: 15
                }
            },
            barWidth: 24,
            data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    setInterval(function() {
        var jsonData = [{ "class": "新浪微博", "number": 502386291+parseInt(Math.random()*6123) },
            { "class": "腾讯微博", "number": parseInt(7440000+Math.random()*287) },
            { "class": "微信公众号", "number": parseInt(236837506+Math.random()*4303) },
            { "class": "新闻客户端", "number":parseInt(242975+Math.random()*5) },
            { "class": "音视频", "number": parseInt(272983053+Math.random()*2)},
            { "class": "境外新闻", "number":parseInt(134690+(Math.random()*149)) },
            { "class": "国内新闻", "number": parseInt(193012810+Math.random()*2) },
            { "class": "国内博客", "number": parseInt(33845140+Math.random()*22) },
            { "class": "国内论坛", "number": parseInt(22874347+Math.random()*339)}
        ];
        var optionData = cqrbdp.getOptionDataByRaw(jsonData); //设置统计图options内的数据

        var series = myChart.getSeries();
        series[0].data = optionData;
        myChart.setSeries(series, 'notMerge');
    }, 1000);
}

cqrbdp.drawTodyBar = function() {
    var myChart = echarts.init(document.getElementById('barmain'));
    //全局调色板，按新闻、论坛、微信、新浪微博、腾讯微博顺序
    var colors = ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'];
    var option = {
        title: {
            show: false,
            top: 'top',
            left: 'center',
            text: '今日数据量',
            textStyle: {
                color: '#fff',
                fontWeight: 'bold',
                fontSize: 16
            }
        },
        grid: {
            show: false,
            x: 160,
            y: 50,
            containLabel: false,
            height: 230,
            width: 385,
            borderColor: 'rgba(0,0,0,0)'
        },
        tooltip: {
            show: true,
            showContent: true,
            trigger: 'axis',
            formatter: '{b}: {c}'
        },
        xAxis: [{
            type: 'category',
            boundaryGap: true,
            show:false,
            axisLine: {
                show: true,
                onZero: false,
                lineStyle: {
                    color: '#6acce4',
                    width: 1
                }
            },
            axisTick: {
                show: false,
                inside: false,
                lineStyle: {
                    color: '#6acce4',
                }
            },
            axisLabel: {
                show: true,
                interval: 0,
                margin: 25,
                textStyle: {
                    color: '#fff',
                    fontWeight: 'bold',
                    fontSize: 15
                }
            },
            splitLine: {
                show: false,
            },
            splitArea: {
                show: false,
                interval: 0
            },
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客']
        }],
        yAxis: [{
            type: 'value',
            axisLine: {
                show: true,
                onZero: false,
                lineStyle: {
                    color: '#6acce4',
                    width: 1
                }
            },
            axisTick: {
                show: true,
                lineStyle: {
                    color: '#6acce4',
                }
            },
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#6acce4'
                },
                // formatter: function(value, index) {
                //     if (value / 10000 >= 1 && value / 10000 < 100) {
                //         return (value / 10000) + "W";
                //     } else if (value / 1000000 >= 1) {
                //         return (value / 1000000) + "M";
                //     };
                //     return value;
                // }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#3B3E43'
                }
            },
        }],
        series: [{
            name: '数据量',
            type: 'bar',
            legendHoverLink: false,
            itemStyle: {
                normal: {
                    // barBorderRadius: 15,
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}',
                        textStyle: {
                            color: '#99D4ED',
                            fontSize: 14
                        }
                    },
                    color: function(param) {
                        return colors[param.dataIndex];
                    }
                },
                emphasis: {
                    // barBorderRadius: 15
                }
            },
            barWidth: 24,
            data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);


    //请求获得数据，成功后更新统计图
    $.get('url', 'data', function(json) {
        var rawData = json.result; //查询返回的数据
        // var rawData = [
        //     { "class": "新闻", "number": "1585350" },
        //     { "class": "论坛", "number": "635350" },
        //     { "class": "微信", "number": "2635350" },
        //     { "class": "新浪微博", "number": "4535350" },
        //     { "class": "腾讯微博", "number": "2635350" }
        // ];
        var optionData = cqrbdp.getOptionDataByRaw(rawData); //设置统计图options内的数据

        var series = myChart.getSeries();
        series[0].data = optionData;
        myChart.setSeries(series, 'notMerge');
    });

}

//格式化数据需要按照新闻、论坛、微信、新浪、腾讯的顺序
cqrbdp.getOptionDataByRaw = function(rawData) {
    // var result = [];
    var orderObj = [{ //将rawData排序
        name: '新浪微博'
    }, {
        name: '腾讯微博'
    }, {
        name: '微信公众号'
    }, {
        name: '新闻客户端'
    }, {
        name: '音视频'
    },{
        name: '境外新闻'
    },{
        name: '国内新闻'
    },{
        name: '国内博客'
    },{
        name: '国内论坛'
    }];
    var tempData = {};
    for (var i = 0; i < rawData.length; i++) {
        tempData[rawData[i].class] = rawData[i].number;
    }
    for (var i = 0; i < orderObj.length; i++) {
        orderObj[i].value = tempData[orderObj[i].name];
    }
    return orderObj;
}
